登录 白背景

https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/submissions/

class Solution:
    def letterCombinations(self, digits: str) -> List[str]:
        ret = []
        phone = {'2': ['a', 'b', 'c'],
                 '3': ['d', 'e', 'f'],
                 '4': ['g', 'h', 'i'],
                 '5': ['j', 'k', 'l'],
                 '6': ['m', 'n', 'o'],
                 '7': ['p', 'q', 'r', 's'],
                 '8': ['t', 'u', 'v'],
                 '9': ['w', 'x', 'y', 'z']}
        for num in digits:
            # print('num',num)
            if ret == []:
                ret = phone[num][:]
                continue
            length = len(ret)
            for letter in phone[num]:
                # print('letter',letter)
                for existStr in ret[:length]:
                    # print('existStr',existStr)
                    ret.append(existStr + letter)
            ret = ret[length:]
        return ret